package com.zhiche.lisa.tms.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zhiche.lisa.config.ValidXmlResult;
import com.zhiche.lisa.core.enums.TableStatusEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.tms.dao.model.UploadCapital;
import com.zhiche.lisa.tms.dto.CompossCapitalFlowSendToProvinceDTO;
import com.zhiche.lisa.tms.service.ICapitalFlowSheetService;
import com.zhiche.lisa.tms.service.SendMsgService;
import com.zhiche.lisa.tms.service.UploadCapitalService;
import com.zhiche.lisa.tms.vo.CompossCapitalFinancialList;
import com.zhiche.lisa.tms.vo.CompossCapitalFlowShipNote;
import com.zhiche.lisa.util.Soap1_1client;
import com.zhiche.lisa.util.SystemConstants;
import com.zhiche.lisa.util.UniquenessFlagUnits;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Wrapper;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 资金流水单上报省平台方法实现类
 */
@Service
public class CapitalFlowSheetImp implements ICapitalFlowSheetService {

    Logger logger = Logger.getLogger(CapitalFlowSheetImp.class);
    @Autowired
    UploadCapitalService uploadCapitalService;
    @Autowired
    SendMsgService sendMsgService;
//
//    @Autowired
//    private ICaptialFlowLogSheetDao captialFlowLogSheetDao;
//
//    @Autowired
//    private SessionFactory sessionFactory;

    @Override
    public void saveOrUpdate(MultipartFile cityFile) {
        // TODO Auto-generated method stub

    }

    /**
     * 资金流水单上报省平台
     *
     * @param capitalFlowSendToProvinceDTO 资金流水单对象
     * @return
     * @throws Exception
     */
    @Override
    public Map<String, Object> updateXMLMessage_Province(CompossCapitalFlowSendToProvinceDTO capitalFlowSendToProvinceDTO) throws Exception {
        //CompossCapitalFlowSendToProvinceDTO capitalFlowSendToProvinceDTO = getXmlParams();
        //ValidXmlResult xmlMsgRes = getCheckResult(capitalFlowSendToProvinceDTO);
// 上传信息
        EntityWrapper<UploadCapital> ew = new EntityWrapper<>();
        ew.eq("deal_status", "0");

        List<UploadCapital> uploadCapitals = uploadCapitalService.selectList(ew);
//        List<UploadCapital> uploadCapitalHeard = uploadCapitalService.groupPlateAndcustOrder();

        for (UploadCapital uploadCapital : uploadCapitals) {
            CompossCapitalFlowSendToProvinceDTO compossCapitalFlowSendToProvinceDTO = new CompossCapitalFlowSendToProvinceDTO();
            compossCapitalFlowSendToProvinceDTO.setMethodIdentifier("StFinancialService.subFinancial");                   // set报文方法名称
            compossCapitalFlowSendToProvinceDTO.setCarrier(SystemConstants.SYS_NOCARCARRIER_XML_CARRIER);                 // set承运人
            compossCapitalFlowSendToProvinceDTO.setSenderCode(SystemConstants.SYS_NOCARCARRIER_XML_SENDERCODE);           // set无车承运人交换代码
            compossCapitalFlowSendToProvinceDTO.setDocumentName("资金流水单");                                             // set单据名称
            // 生成单据号
            String documentNumber = UniquenessFlagUnits.generateUniquenessFlag("KBSARPAY");
            compossCapitalFlowSendToProvinceDTO.setDocumentNumber(documentNumber);                                        // set单据号
            compossCapitalFlowSendToProvinceDTO.setRecCarrier(uploadCapital.getPayee());                      // set实际收款人
            compossCapitalFlowSendToProvinceDTO.setVehicleNumber(uploadCapital.getCarNo());                                                  // set车牌号
            compossCapitalFlowSendToProvinceDTO.setLicensePlateTypeCode("01");                                            // set车牌分类代码
            compossCapitalFlowSendToProvinceDTO.setPstatus("0");
            // set标记状态
            List<CompossCapitalFinancialList> compossCapitalFinancialListList = new ArrayList<CompossCapitalFinancialList>();
            List<CompossCapitalFlowShipNote> compossCapitalFlowShipNoteList = new ArrayList<>();
            // set订单信息
            CompossCapitalFlowShipNote compossCapitalFlowShipNote = new CompossCapitalFlowShipNote();
            compossCapitalFlowShipNote.setShippingNoteNumber(uploadCapital.getSysOrderId());                                                     // 订单号
            compossCapitalFlowShipNote.setRemark("2018年运单");
            compossCapitalFlowShipNoteList.add(compossCapitalFlowShipNote);
            // set资金流水关联运单

            CompossCapitalFinancialList compossCapitalFinancialList = new CompossCapitalFinancialList();
            compossCapitalFinancialList.setPaymentMeansCode(uploadCapital.getPaytype());   // 付款方式code
            compossCapitalFinancialList.setBankCode(uploadCapital.getBankcode());                   // 银行代码
            compossCapitalFinancialList.setSequenceCode(uploadCapital.getSerialNumber());           // 流水号
            compossCapitalFinancialList.setMonetaryAmount(String.valueOf(uploadCapital.getMoney().setScale(3, BigDecimal.ROUND_HALF_UP)));                                                                                           // 金额
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
            compossCapitalFinancialList.setDateTime(formatter.format(uploadCapital.getTransferTime())); // 日期时间
            compossCapitalFinancialListList.add(compossCapitalFinancialList);
//            }

//        List<UploadCapital> uploadCapitalHeard = uploadCapitalService.groupPlateAndcustOrder();
//
//        for (UploadCapital uploadCapital : uploadCapitalHeard) {
//            CompossCapitalFlowSendToProvinceDTO compossCapitalFlowSendToProvinceDTO = new CompossCapitalFlowSendToProvinceDTO();
//            compossCapitalFlowSendToProvinceDTO.setMethodIdentifier("StFinancialService.subFinancial");                   // set报文方法名称
//            compossCapitalFlowSendToProvinceDTO.setCarrier(SystemConstants.SYS_NOCARCARRIER_XML_CARRIER);                 // set承运人
//            compossCapitalFlowSendToProvinceDTO.setSenderCode(SystemConstants.SYS_NOCARCARRIER_XML_SENDERCODE);           // set无车承运人交换代码
//            compossCapitalFlowSendToProvinceDTO.setDocumentName("资金流水单");                                             // set单据名称
//            // 生成单据号
//            String documentNumber = UniquenessFlagUnits.generateUniquenessFlag("KBSARPAY");
//            compossCapitalFlowSendToProvinceDTO.setDocumentNumber(documentNumber);                                        // set单据号
//            compossCapitalFlowSendToProvinceDTO.setRecCarrier(uploadCapital.getPayee());                      // set实际收款人
//            compossCapitalFlowSendToProvinceDTO.setVehicleNumber(uploadCapital.getCarNo());                                                  // set车牌号
//            compossCapitalFlowSendToProvinceDTO.setLicensePlateTypeCode("01");                                            // set车牌分类代码
//            compossCapitalFlowSendToProvinceDTO.setPstatus("0");
//            // set标记状态
//            EntityWrapper<UploadCapital> ew = new EntityWrapper<>();
//            ew.eq("carNo",uploadCapital.getCarNo()).eq("cust_order_id",uploadCapital.getCustOrderId());
//            List<UploadCapital> uploadCapitals = uploadCapitalService.selectList(ew);
//            List<CompossCapitalFinancialList> compossCapitalFinancialListList = new ArrayList<CompossCapitalFinancialList>();
//            List<CompossCapitalFlowShipNote> compossCapitalFlowShipNoteList = new ArrayList<>();
//            for (UploadCapital capital : uploadCapitals) {
//                // set订单信息
//                CompossCapitalFlowShipNote compossCapitalFlowShipNote = new CompossCapitalFlowShipNote();
//                compossCapitalFlowShipNote.setShippingNoteNumber(capital.getSysOrderId());                                                     // 订单号
//                compossCapitalFlowShipNoteList.add(compossCapitalFlowShipNote);
//                                         // set资金流水关联运单
//
//                CompossCapitalFinancialList compossCapitalFinancialList = new CompossCapitalFinancialList();
//                compossCapitalFinancialList.setPaymentMeansCode(capital.getPaytype());   // 付款方式code
//                compossCapitalFinancialList.setBankCode(capital.getBankcode());                   // 银行代码
//                compossCapitalFinancialList.setSequenceCode(capital.getSerialNumber());           // 流水号
//                compossCapitalFinancialList.setMonetaryAmount(String.valueOf(capital.getMoney()));                                                                                           // 金额
//                SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
//                compossCapitalFinancialList.setDateTime(formatter.format(capital.getTransferTime())); // 日期时间
//                compossCapitalFinancialListList.add(compossCapitalFinancialList);
//            }
            compossCapitalFlowSendToProvinceDTO.setFinancialList(compossCapitalFinancialListList);
            compossCapitalFlowSendToProvinceDTO.setShipNoteList(compossCapitalFlowShipNoteList);
            String xml = splicXML_Province(compossCapitalFlowSendToProvinceDTO);
            String responseList = sendMsgService.sendToProvince(xml);
            try {
                if (!StringUtils.isEmpty(responseList)) {
                    responseList = responseList.replace("&lt;", "<").replace("&gt;", ">");
                    responseList = responseList.replaceAll("&", "&amp;");
                    Document doc = DocumentHelper.parseText(responseList);
                    Map resMap = Soap1_1client.Dom2Map(doc);
                    if (resMap.get("isSuccess").equals("true")) {
                        Map data = (Map) resMap.get("data");
                        if (StringUtils.isEmpty(data.get("successFinanceFlows"))) {
                            Map failList = (Map) data.get("failList");
                            Map failFinancialFlow = (Map) failList.get("failFinancialFlow");
                            resMap.put("isSuccess", "false");
                            resMap.put("code", null);//code:200 成功；null 失败
                            resMap.put("description", failFinancialFlow.get("reason").toString());
                            logger.info("资金流水单上报失败" + failFinancialFlow.get("reason").toString());
                            throw new BaseException("资金流水单上报失败" + failFinancialFlow.get("reason").toString());
                        } else {
                            ew.eq("sys_order_id",uploadCapital.getSysOrderId()).eq("cust_order_id",uploadCapital.getCustOrderId()).eq("carNo",uploadCapital.getCarNo());
                            uploadCapital.setDealStatus("1");
                            uploadCapital.setDealTime(new Date());
                            uploadCapitalService.updateById(uploadCapital);
                            logger.info("资金流水单上报成功！");
                        }
                    }
                }
            } catch (DocumentException e) {
                logger.error("资金流水单上报省平台  DocumentException：" + e.getMessage());
                throw new BaseException("资金流水单上报省平台失败" + e.getMessage());
            }
            logger.info("上报省监测平台:" + responseList);
        }
        return null;
    }

    private CompossCapitalFlowSendToProvinceDTO getXmlParams() {
        CompossCapitalFlowSendToProvinceDTO compossCapitalFlowSendToProvinceDTO = new CompossCapitalFlowSendToProvinceDTO();
        compossCapitalFlowSendToProvinceDTO.setCarrier("深圳市康舶司科技有限公司");
        compossCapitalFlowSendToProvinceDTO.setSenderCode("14396");
        compossCapitalFlowSendToProvinceDTO.setDocumentName("资金流水单");
        compossCapitalFlowSendToProvinceDTO.setDocumentNumber("313145343235");
        compossCapitalFlowSendToProvinceDTO.setRecCarrier("张强");
        compossCapitalFlowSendToProvinceDTO.setVehicleNumber("浙A32153");
        compossCapitalFlowSendToProvinceDTO.setLicensePlateTypeCode("01");
        compossCapitalFlowSendToProvinceDTO.setPstatus("0");
        CompossCapitalFlowShipNote capitalFlowShipNote1 = new CompossCapitalFlowShipNote();
        capitalFlowShipNote1.setShippingNoteNumber("532237");
        capitalFlowShipNote1.setRemark("2018年运单");
        CompossCapitalFlowShipNote capitalFlowShipNote2 = new CompossCapitalFlowShipNote();
        capitalFlowShipNote2.setShippingNoteNumber("732208");
        capitalFlowShipNote2.setRemark("2018年运单");

        List<CompossCapitalFlowShipNote> capitalFlowShipNoteList = new ArrayList<>();
        capitalFlowShipNoteList.add(capitalFlowShipNote1);
        capitalFlowShipNoteList.add(capitalFlowShipNote2);

        CompossCapitalFinancialList capitalFinancialList1 = new CompossCapitalFinancialList();
        capitalFinancialList1.setPaymentMeansCode("39");
        capitalFinancialList1.setBankCode("ICBK");
        capitalFinancialList1.setSequenceCode("2114097578211423");
        capitalFinancialList1.setMonetaryAmount("1500.258");
        capitalFinancialList1.setDateTime("20180102144526");
        CompossCapitalFinancialList capitalFinancialList2 = new CompossCapitalFinancialList();
        capitalFinancialList2.setPaymentMeansCode("39");
        capitalFinancialList2.setBankCode("ICBK");
        capitalFinancialList2.setSequenceCode("2114097578211424");
        capitalFinancialList2.setMonetaryAmount("1520.258");
        capitalFinancialList2.setDateTime("20180102144526");

        List<CompossCapitalFinancialList> financialList = new ArrayList<>();
        financialList.add(capitalFinancialList1);
        financialList.add(capitalFinancialList2);

        compossCapitalFlowSendToProvinceDTO.setShipNoteList(capitalFlowShipNoteList);
        compossCapitalFlowSendToProvinceDTO.setFinancialList(financialList);
        return compossCapitalFlowSendToProvinceDTO;

    }

//    /**
//     * 资金流水单校验
//     * @param body
//     * @return
//     */
//    private ValidXmlResult getCheckResult(CompossCapitalFlowSendToProvinceDTO body) {
//        ValidXmlResult validXmlResult = new ValidXmlResult();
//
//        String failMsg = "";
//        boolean isValid = false;
//        String xml = "";
//
//        String carrier = body.getCarrier();
//        if (ValidUtils.isEmptyStr(carrier)) {
//            failMsg = "企业名称为空：" + body.getDocumentNumber();
//            logger.info("企业名称为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        String senderCode = body.getSenderCode();
//        if (ValidUtils.isEmptyStr(senderCode)) {
//            failMsg = "企业交换代码为空：" + body.getDocumentNumber();
//            logger.info("企业交换代码为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        String documentName = body.getDocumentName();
//        if (ValidUtils.isEmptyStr(documentName)) {
//            failMsg = "单证名称为空：" + body.getDocumentNumber();
//            logger.info("单证名称为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//        String documentNumber = body.getDocumentNumber();
//        if (ValidUtils.isEmptyStr(documentNumber)) {
//            failMsg = "单证号为空!";
//            logger.info("单证号为空!");
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//        String recCarrier = body.getRecCarrier();
//        if (ValidUtils.isEmptyStr(recCarrier)) {
//            failMsg = "实际收款人为空：" + body.getDocumentNumber();
//            logger.info("实际收款人为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//        String vehicleNumber = body.getVehicleNumber();
//        if (ValidUtils.isEmptyStr(vehicleNumber)) {
//            failMsg = "车辆牌照号为空：" + body.getDocumentNumber();
//            logger.info("车辆牌照号为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        String licensePlateTypeCode = body.getLicensePlateTypeCode();
//        if (ValidUtils.isEmptyStr(licensePlateTypeCode)) {
//            failMsg = "拍照类型代码为空：" + body.getDocumentNumber();
//            logger.info("拍照类型代码为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        String pstatus = body.getPstatus();
//        if (ValidUtils.isEmptyStr(pstatus)) {
//            failMsg = "标记状态为空：" + body.getDocumentNumber();
//            logger.info("标记状态为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        List<CompossCapitalFlowShipNote> shipNoteList = body.getShipNoteList();
//        if (CollectionUtils.isEmpty(shipNoteList)) {
//            failMsg = "运单列表为空：" + body.getDocumentNumber();
//            logger.info("运单列表为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        for (CompossCapitalFlowShipNote capitalFlowShipNote : shipNoteList) {
//
//            String shippingNoteNumber = capitalFlowShipNote.getShippingNoteNumber();
//            if (ValidUtils.isEmptyStr(shippingNoteNumber)) {
//                failMsg = "托运单号为空：" + body.getDocumentNumber();
//                logger.info("托运单号为空：" + body.getDocumentNumber());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//        }
//
//        List<CompossCapitalFinancialList> financialList = body.getFinancialList();
//        if (financialList.size() < 1) {
//            failMsg = "财务列表为空：" + body.getDocumentNumber();
//            logger.info("财务列表为空：" + body.getDocumentNumber());
//            validXmlResult.setFailReason(failMsg);
//            validXmlResult.setValid(isValid);
//            validXmlResult.setXml(xml);
//            return validXmlResult;
//        }
//
//        for (CompossCapitalFinancialList capitalFinancialList : financialList) {
//
//            String paymentMeansCode = capitalFinancialList.getPaymentMeansCode();
//            if (ValidUtils.isEmptyStr(paymentMeansCode)) {
//                failMsg = "付款方式代码为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode();
//                logger.info("付款方式代码为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//
//            String bankCode = capitalFinancialList.getBankCode();
//            if ("39".equals(paymentMeansCode) && ValidUtils.isEmptyStr(bankCode)) {
//                failMsg = "银行代码为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode();
//                logger.info("银行代码为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//
//            String sequenceCode = capitalFinancialList.getSequenceCode();
//            if (ValidUtils.isEmptyStr(sequenceCode)) {
//                failMsg = "资金流水单号为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode();
//                logger.info("资金流水单号为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//            String monetaryAmount = capitalFinancialList.getMonetaryAmount();
//            if (ValidUtils.isEmptyStr(monetaryAmount)) {
//                failMsg = "货币金额为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode();
//                logger.info("货币金额为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//            String dateTime = capitalFinancialList.getDateTime();
//            if (ValidUtils.isEmptyStr(dateTime)) {
//                failMsg = "日期时间为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode();
//                logger.info("日期时间为空：" + body.getDocumentNumber() + "--" + capitalFinancialList.getSequenceCode());
//                validXmlResult.setFailReason(failMsg);
//                validXmlResult.setValid(isValid);
//                validXmlResult.setXml(xml);
//                return validXmlResult;
//            }
//        }
//
//        xml = splicXML_Province(body);
//        validXmlResult.setFailReason(failMsg);
//        validXmlResult.setValid(true);
//        validXmlResult.setXml(xml);
//        return validXmlResult;
//    }

    /**
     * 省平台资金流水报文
     *
     * @param body
     * @return
     */
    private String splicXML_Province(CompossCapitalFlowSendToProvinceDTO body) {

        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        sb.append("<root>");
        sb.append("<header>");
        sb.append("<methodIdentifier>StFinancialService.subFinancial</methodIdentifier>");
        sb.append("</header>");
        sb.append("<body>");

        for (int i = 0; i < 1; i++) {
            sb.append("<financeFlow>");
            sb.append("<carrier>" + body.getCarrier() + "</carrier>");
            sb.append("<senderCode>" + body.getSenderCode() + "</senderCode>");
            sb.append("<documentName>" + body.getDocumentName() + "</documentName>");
            sb.append("<documentNumber>" + body.getDocumentNumber() + "</documentNumber>");
            sb.append("<recCarrier>" + body.getRecCarrier() + "</recCarrier>");
            sb.append("<vehicleNumber>" + body.getVehicleNumber() + "</vehicleNumber>");
            sb.append("<licensePlateTypeCode>" + body.getLicensePlateTypeCode() + "</licensePlateTypeCode>");
            sb.append("<pstatus>" + body.getPstatus() + "</pstatus>");

            List<CompossCapitalFlowShipNote> shipNoteList = body.getShipNoteList();

            for (int j = 0; j < shipNoteList.size(); j++) {
                sb.append("<shippingNoteList>");
                sb.append("<shippingNoteNumber>" + (shipNoteList.get(j).getShippingNoteNumber().length() > 20 ? shipNoteList.get(j).getShippingNoteNumber().substring(0, 21) : shipNoteList.get(j).getShippingNoteNumber()) + "</shippingNoteNumber>");
                sb.append("<remark>" + shipNoteList.get(j).getRemark() + "</remark>");
                sb.append("</shippingNoteList>");
            }

            List<CompossCapitalFinancialList> financialList = body.getFinancialList();

            for (int k = 0; k < financialList.size(); k++) {
                sb.append("<financialList>");
                sb.append("<paymentMeansCode>" + financialList.get(k).getPaymentMeansCode() + "</paymentMeansCode>");
                sb.append("<bankCode>" + financialList.get(k).getBankCode() + "</bankCode>");
                sb.append("<sequenceCode>" + financialList.get(k).getSequenceCode() + "</sequenceCode>");
                sb.append("<monetaryAmount>" + financialList.get(k).getMonetaryAmount() + "</monetaryAmount>");
                sb.append("<dateTime>" + financialList.get(k).getDateTime() + "</dateTime>");
                sb.append("</financialList>");

            }

            sb.append("</financeFlow>");
        }
//		for (int i = 0; i < 1; i++) {
//			sb.append("<financeFlow>");
//			sb.append("<carrier>"+"广州达到运输公司"+"</carrier>");
//			sb.append("<senderCode>"+"1415"+"</senderCode>");
//			sb.append("<documentName>"+"资金流水单"+"</documentName>");
//			sb.append("<documentNumber>"+"31314534233"+(5+i)+"</documentNumber>");
//			sb.append("<recCarrier>"+"张强"+"</recCarrier>");
//			sb.append("<vehicleNumber>"+"浙A32153"+"</vehicleNumber>");
//			sb.append("<licensePlateTypeCode>"+"01"+"</licensePlateTypeCode>");
//			sb.append("<pstatus>"+"0"+"</pstatus>");
//
//			for(int j = 0; j < 2; j++){
//				sb.append("<shippingNoteList>");
//				sb.append("<shippingNoteNumber>"+"53213"+(5+j)+"</shippingNoteNumber>");
//				sb.append("<remark>"+"2018年运单"+"</remark>");
//				sb.append("</shippingNoteList>");
//			}
//			for(int k = 0; k < 2; k++){
//				sb.append("<financialList>");
//				sb.append("<paymentMeansCode>"+"39"+"</paymentMeansCode>");
//				sb.append("<bankCode>"+"ICBK"+"</bankCode>");
//				sb.append("<sequenceCode>"+"211409757821041"+(7+k)+"</sequenceCode>");
//				sb.append("<monetaryAmount>"+"1500.568"+"</monetaryAmount>");
//				sb.append("<dateTime>"+"20180320151826"+"</dateTime>");
//				sb.append("</financialList>");
//
//			}
//
//			sb.append("</financeFlow>");
//		}
        sb.append("</body>");
        sb.append("</root>");

        return sb.toString();
    }
}
